package com.szp.lagou.dubbo.filerDemo.consumer.controller;

import com.szp.lagou.dubbo.filerDemo.Context.IpContext;
import com.szp.lagou.dubbo.filerDemo.provider.service.GoodByeService;
import com.szp.lagou.dubbo.filerDemo.provider.service.HelloService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {
    @Reference
    HelloService helloService;
    @Reference
    GoodByeService goodByeService;
    @RequestMapping("/hello")
    public String hello(@RequestParam("name") String name, HttpServletRequest request){
//        String clientIp = request.getRemoteAddr();
//        IpContext.getContext().setClientIp(clientIp);
        String hello = helloService.sayHello(name);
        String goobye = goodByeService.sayGoodBye(name);
        return hello + "+" + goobye;
    }
}
